'use strict';

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

var vue = new Vue({
    data: {
        form: {
            old_password: '',
            new_password: '',
            new_password2: ''
        }
    },
    methods: {
        onSubmit: function () {
            var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
                var response, data;
                return regeneratorRuntime.wrap(function _callee$(_context) {
                    while (1) {
                        switch (_context.prev = _context.next) {
                            case 0:
                                if (this.form.old_password) {
                                    _context.next = 3;
                                    break;
                                }

                                this.$message({
                                    type: 'error',
                                    message: '旧密码不能为空'
                                });
                                return _context.abrupt('return');

                            case 3:
                                if (this.form.new_password) {
                                    _context.next = 6;
                                    break;
                                }

                                this.$message({
                                    type: 'error',
                                    message: '新密码不能为空'
                                });
                                return _context.abrupt('return');

                            case 6:
                                if (this.form.new_password2) {
                                    _context.next = 9;
                                    break;
                                }

                                this.$message({
                                    type: 'error',
                                    message: '再次新密码不能为空'
                                });
                                return _context.abrupt('return');

                            case 9:
                                if (!(this.form.new_password != this.form.new_password2)) {
                                    _context.next = 12;
                                    break;
                                }

                                this.$message({
                                    type: 'error',
                                    message: '两次新密码不一致'
                                });
                                return _context.abrupt('return');

                            case 12:
                                _context.prev = 12;
                                _context.next = 15;
                                return axios.post('/api/safe/change_password', this.form);

                            case 15:
                                response = _context.sent;
                                data = response.data;

                                if (parseInt(data.code) > 0) {
                                    this.$message({
                                        message: data.msg,
                                        type: "success",
                                        duration: 1000
                                    });
                                    this.form.old_password = "";
                                    this.form.new_password = "";
                                    this.form.new_password2 = "";
                                } else {
                                    this.$message.error(data.msg);
                                }
                                _context.next = 23;
                                break;

                            case 20:
                                _context.prev = 20;
                                _context.t0 = _context['catch'](12);

                                this.$message.error(_context.t0.toString());

                            case 23:
                            case 'end':
                                return _context.stop();
                        }
                    }
                }, _callee, this, [[12, 20]]);
            }));

            function onSubmit() {
                return _ref.apply(this, arguments);
            }

            return onSubmit;
        }()
    },
    created: function created() {},
    mounted: function () {
        var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
            return regeneratorRuntime.wrap(function _callee2$(_context2) {
                while (1) {
                    switch (_context2.prev = _context2.next) {
                        case 0:

                            this.$check_login();

                        case 1:
                        case 'end':
                            return _context2.stop();
                    }
                }
            }, _callee2, this);
        }));

        function mounted() {
            return _ref2.apply(this, arguments);
        }

        return mounted;
    }()
}).$mount('#app');